<script lang="ts" setup>
defineOptions({ name: 'DelConfirmDialog' })

const content = ref()
const currentId = ref()
const confirmButtonText = ref('删除')
/** 打开弹窗 */
const open = async (id: number, text: string[], buttonText?:string) => {
  dialogVisible.value = true
  content.value = text
  currentId.value = id
  if (buttonText) {
    confirmButtonText.value = buttonText
  }
}
defineExpose({ open }) // 提供 open 方法，用于打开弹窗

const dialogVisible = ref(false) // 弹窗的是否展示
/** 触发 */
const emit = defineEmits(['confirm']) // 定义 confirm 事件，用于操作成功后的回调
const submitForm = () => {
  emit('confirm', currentId.value)
  dialogVisible.value = false
}
</script>

<template>
  <ElDialog
    v-model="dialogVisible"
    :close-on-click-modal="true"
    width="360px"
    destroy-on-close
    lock-scroll
    draggable
    center
    class="no-header-dialog" 
    :show-close="false"
    :show-header="false"
  >
      <div class="del-content">
        <Icon
            icon="ep:info-filled"
            class="del-icon"
            color="#EEA02A"
            :size='32'
          />
          <div class="del-text">
            <div v-for="(text, index) in content" :key="index">{{ text }}</div>
          </div>
      </div>

      <template #footer>
        <el-button @click="dialogVisible = false">取消</el-button>
        <el-button @click="submitForm" type="danger">{{ confirmButtonText }}</el-button>
      </template>
  </ElDialog>
</template>

<style lang="scss">
.no-header-dialog {
  .#{$elNamespace}-overlay-dialog {
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .#{$elNamespace}-dialog {
    margin: 0 !important;

    &__header {
      height: 54px;
      padding: 0;
      margin-right: 0 !important;
      border-bottom: 1px solid var(--el-border-color);
    }

    &__body {
      padding: 15px !important;
    }

    &__footer {
      // border-top: 1px solid var(--el-border-color);
    }

    &__headerbtn {
      top: 0;
    }
  }
  .el-dialog__header {
    display: none;
  }
  // .el-dialog__header {
  //   display: none;
  // }
  .del-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    .del-icon {
    }
    .del-text {
      line-height: 22px;
      margin-top: 16px;
    }
  }
}
</style>
